using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace Tryit.Models
{
    public class Material : INotifyPropertyChanged
    {
        private string _name;
        private string _description;
        private DateTime _createTime;
        private DateTime _updateTime;
        private ObservableCollection<MaterialElement> _elements;

        public string Name
        {
            get => _name;
            set => SetProperty(ref _name, value);
        }

        public string Description
        {
            get => _description;
            set => SetProperty(ref _description, value);
        }

        public DateTime CreateTime
        {
            get => _createTime;
            set => SetProperty(ref _createTime, value);
        }

        public DateTime UpdateTime
        {
            get => _updateTime;
            set => SetProperty(ref _updateTime, value);
        }

        public ObservableCollection<MaterialElement> Elements
        {
            get => _elements;
            set => SetProperty(ref _elements, value);
        }

        public Material()
        {
            _elements = new ObservableCollection<MaterialElement>();
            _createTime = DateTime.Now;
            _updateTime = DateTime.Now;
        }

        public Material(string name, string description = "") : this()
        {
            _name = name;
            _description = description;
        }

        public event PropertyChangedEventHandler? PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
        {
            if (Equals(field, value)) return false;
            field = value;
            OnPropertyChanged(propertyName);
            return true;
        }
    }
} 